window.reliers.push("angularFileUpload");
corpApp.controller('controller',['$scope', '$modal', 'upserve','reference', 'ngDialog','$upload', function($scope, $modal, upserve,reference, ngDialog, $upload, $http){
	
	$scope.attachments = new Array();
	$scope.dels = new Array();
	
	$scope.uploadAttachments = function (files) {
        if (files && files.length) {
            for (var i = 0; i < files.length; i++) {
                var file = files[i];
                $upload.upload({
                        url: $path$+'/admin/uploadAttachments',
                    fields: { dirname: 'items' },
                    file: file
                }).progress(function (evt) {
                    var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
                    console.log('progress: ' + progressPercentage + '% ' + evt.config.file.name);
                }).success(function (data, status, headers, config) {
                	if(data.success){
                		$scope.attachments.push(data);
                	}
                });
            }
        }
    };
    //删除上传的附件
    $scope.delAttachment = function(o, index){
		var o = $scope.attachments.splice(index, 1);
		angular.forEach(o, function(val){
			$scope.dels.push(val);
		});
	}
	
}]);